package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seawaterbt.ssm.config.DataSource;
import com.seawaterbt.ssm.config.DataSourceEnum;
import com.seawaterbt.ssm.entity.BasCommunity;
import com.seawaterbt.ssm.entity.CzBasBoiler;
import com.seawaterbt.ssm.entity.ShengBas_Community;
import com.seawaterbt.ssm.entity.ShengBas_building;
import com.seawaterbt.ssm.mapper.ShengBasBuildingMapper;
import com.seawaterbt.ssm.mapper.ShengBasCommunityMapper;
import com.seawaterbt.ssm.service.CzBasCommunityService;
import com.seawaterbt.ssm.service.ShengBasBuildingService;
import com.seawaterbt.ssm.service.ShengBasCommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service

public class ShengBasCommunityServiceImpl extends ServiceImpl<ShengBasCommunityMapper, ShengBas_Community> implements ShengBasCommunityService {
    @Autowired
    CzBasCommunityService czBasCommunityService;
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean save(ShengBas_Community entity) {
        return super.save(entity);
    }
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean saveOrUpdate(ShengBas_Community entity) {
        return super.saveOrUpdate(entity);
    }

    @Override
    public void toSend() {
        QueryWrapper<BasCommunity> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("code", 130981011).or().likeRight("code", 130903007);
        List<BasCommunity> czlist = czBasCommunityService.list(queryWrapper);
        if (czlist != null) {
            for (BasCommunity basCommunity : czlist) {
                ShengBas_Community shengBas_community = new ShengBas_Community();
                shengBas_community.setAddTime(basCommunity.getCreateTime());
                shengBas_community.setAemark(basCommunity.getNote());
                shengBas_community.setCommunityAddress(basCommunity.getAddress());
                shengBas_community.setCommunityId(basCommunity.getCodeProvince());
                shengBas_community.setCommunityName(basCommunity.getCommunityName());
                if (!StringUtils.isEmpty(basCommunity.getCommunityType())) {
                    int type = 2;
                    if (basCommunity.getCommunityType().equals("居建")) {
                        type = 0;
                    } else if (basCommunity.getCommunityType().equals("公建")) {
                        type = 1;
                    }
                    shengBas_community.setCommunityType(type);
                }
                shengBas_community.setHeatingArea(Double.parseDouble(basCommunity.getHeatingArea()==null?"0.0":basCommunity.getHeatingArea()));
                if (!StringUtils.isEmpty(basCommunity.getCodeProvince())){
                    shengBas_community.setHeatCompanyId(basCommunity.getCodeProvince().substring(0,9));
                    shengBas_community.setHeatstationId(basCommunity.getCodeProvince().substring(0,13));
                }
                shengBas_community.setHouseHoldCont(basCommunity.getHouseHoldCount());
                shengBas_community.setMapx(Double.parseDouble(basCommunity.getMapx()==null?"0":basCommunity.getMapx()));
                shengBas_community.setMapy(Double.parseDouble(basCommunity.getMapy()==null?"0":basCommunity.getMapy()));
                shengBas_community.setRegionalId("130");
                this.save(shengBas_community);
            }
        }
    }
}
